package com.liuweiheng.cloudproviderpayment8002.common.controller;

import com.liuweiheng.base.entity.R;
import com.liuweiheng.base.utils.GlobalStrRedisUtil;
import com.liuweiheng.cloudproviderpayment8002.common.service.BaseService;
import com.liuweiheng.cloudproviderpayment8002.common.service.UserService;
import com.liuweiheng.cloudproviderpayment8002.entity.User;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;

@RestController
@RequestMapping("/payment/test")
@Slf4j
public class TestController {


    @Autowired
    private StringRedisTemplate stringRedisTemplate;

    /**
     * 基础服务接口
     */
    @Autowired
    private BaseService baseService;

    @Autowired
    private UserService userService;

    @GetMapping("/checkUtil")
    public R checkUtil() {
        return R.ok(GlobalStrRedisUtil.getValue("age"));
    }


    @PostMapping("/login")
    public R login(@RequestBody User user) throws IOException {

        R loginResult = baseService.login(user);

        if (loginResult.get(R.CODE).equals(R.SUCCESS_CODE)) {
            return R.ok("auth success").putData(userService.selectUserByUsername(user.getUsername()));
        } else {
//            response.sendRedirect("/base/error");
            return R.error("auth fail");
        }
//        return null;
    }


}
